<?php


namespace App\Http\Controllers\Admin;


use App\Response\Response;
use Illuminate\Http\Request;
use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;

//vip管理
class VipController extends BaseController
{
    /**
     * @api {get} /vip/privilege vip特权列表
     * @apiVersion 0.1.0
     * @apiName vip特权列表
     * @apiGroup vip管理
     *
     * @apiParam {int} page 第几页，默认1
     * @apiParam {int} page_size 每页显示条数，1-100之间，默认10
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "current_page": 1,
     * "data": [{
     * "id": 5,
     * "name（特权名称）": "专属头像框",
     * "status（状态 0禁用 1启用）": "0",
     * "type（特权类型）": 5,
     * "icon_img（特权图标）": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/newadmin/17aec5df92d9cae5eebb9f046777cb7eDF078.png",
     * "dark_icon_img（特权图标暗）": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/newadmin/17aec5df92d9cae5eebb9f046777cb7eDF078.png",
     * "explain_img（特权说明图）": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/newadmin/17aec5df92d9cae5eebb9f046777cb7eDF078.png",
     * "explain1（特权说明）": "会员专属牌面十足",
     * "explain2（特权说明2）": "",
     * "sort（排序）": 2
     * }],
     * "first_page_url": "http://www.qipaoadmin.com/vip/privilege?=1",
     * "from": 1,
     * "last_page": 1,
     * "last_page_url": "http://www.qipaoadmin.com/vip/privilege?=1",
     * "next_page_url": null,
     * "path": "http://www.qipaoadmin.com/vip/privilege",
     * "per_page": 20,
     * "prev_page_url": null,
     * "to": 5,
     * "total": 5
     * },
     * "message": ""
     * }
     */
    public function privilegeList(Request $request)
    {
        $param = $request->only('page', 'page_size');
        $v = app('validator')->make($param, [
            'page' => 'integer|min:1',
            'page_size' => 'integer|min:1|max:100',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $page = $request->input('page', 1);
        $perPage = $request->input('page_size', 20);

        $list = app('repo_vip')->getPrivilegeList($page, $perPage);
        return Response::sendData($list);
    }

    /**
     * @api {post} /vip/privilege/add 新增特权
     * @apiVersion 0.1.0
     * @apiName 新增特权
     * @apiGroup vip管理
     *
     * @apiParam {int} name 特权名称，必传
     * @apiParam {int} status 状态 0禁用 1启用，必传
     * @apiParam {int} type 特权类型，必传
     * @apiParam {int} icon_img 特权图标，必传
     * @apiParam {int} dark_icon_img 特权图标暗，必传
     * @apiParam {int} explain_img 特权说明图，必传
     * @apiParam {int} explain1 特权说明文字1，必传
     * @apiParam {int} explain2 特权说明文字2，必传
     * @apiParam {int} sort 排序，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function privilegeAdd(Request $request)
    {
        $param = $request->only('name', 'status', 'type', 'icon_img', 'dark_icon_img', 'explain_img', 'explain1', 'explain2', 'sort');
        $v = app('validator')->make($param, [
            'name' => 'required|string|max:100',
            'status' => 'required|integer|in:0,1',
            'type' => 'required|integer|min:0',
            'icon_img' => 'required|string|max:255',
            'dark_icon_img' => 'required|string|max:255',
            'explain_img' => 'required|string|max:255',
            'explain1' => 'required|string|max:255',
            'explain2' => 'required|string|max:255',
            'sort' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_vip')->privilegeAdd($param);
        return Response::sendData(true);
    }

    /**
     * @api {get} /vip/privilege/edit_detail 编辑特权数据
     * @apiVersion 0.1.0
     * @apiName 编辑特权数据
     * @apiGroup vip管理
     *
     * @apiParam {Int} id id，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "id": 1,
     * "name（特权名称）": "专属头像框",
     * "status（状态）": "启用",
     * "type（特权类型）": 5,
     * "icon_img（特权图标）": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/newadmin/17aec5df92d9cae5eebb9f046777cb7eDF078.png",
     * "dark_icon_img（特权图标暗）": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/newadmin/17aec5df92d9cae5eebb9f046777cb7eDF078.png",
     * "explain_img（特权说明图）": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/newadmin/17aec5df92d9cae5eebb9f046777cb7eDF078.png",
     * "explain1（特权说明）": "会员专属牌面十足",
     * "explain2（特权说明2）": "",
     * "sort（排序）": 2
     * },
     * "message": ""
     * }
     */
    public function privilegeEditDetail(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_vip')->privilegeEditDetail($param);
        return Response::sendData($list);
    }

    /**
     * @api {post} /vip/privilege/edit 编辑特权
     * @apiVersion 0.1.0
     * @apiName 编辑特权
     * @apiGroup vip管理
     *
     * @apiParam {int} id id，必传
     * @apiParam {int} name 特权名称，必传
     * @apiParam {int} status 状态 0禁用 1启用，必传
     * @apiParam {int} type 特权类型，必传
     * @apiParam {int} icon_img 特权图标，必传
     * @apiParam {int} dark_icon_img 特权图标暗，必传
     * @apiParam {int} explain_img 特权说明图，必传
     * @apiParam {int} explain1 特权说明文字1，必传
     * @apiParam {int} explain2 特权说明文字2，必传
     * @apiParam {int} sort 排序，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function privilegeEdit(Request $request)
    {
        $param = $request->only('id', 'name', 'status', 'type', 'icon_img', 'dark_icon_img', 'explain_img', 'explain1', 'explain2', 'sort');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
            'name' => 'required|string|max:100',
            'status' => 'required|integer|in:0,1',
            'type' => 'required|integer|min:0',
            'icon_img' => 'required|string|max:255',
            'dark_icon_img' => 'required|string|max:255',
            'explain_img' => 'required|string|max:255',
            'explain1' => 'required|string|max:255',
            'explain2' => 'required|string|max:255',
            'sort' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_vip')->privilegeEdit($param);
        return Response::sendData(true);
    }


    /**
     * @api {get} /vip/gradebig vip大等级列表
     * @apiVersion 0.1.0
     * @apiName vip大等级列表
     * @apiGroup vip管理
     *
     * @apiParam {int} page 第几页，默认1
     * @apiParam {int} page_size 每页显示条数，1-100之间，默认10
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "current_page": 1,
     * "data": [{
     * "id": 7,
     * "grade(阶段等级)": "7",
     * "name(等级阶段名称)": "海神",
     * "big_img(展示大图)": "http://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/admin_images/5fd88a8de3cdc.png",
     * "privilege_data(等级特权)": [{
     * "id": 1,
     * "name": "好友红名"
     * },
     * {
     * "id": 2,
     * "name": "身份标识"
     * }
     * ]
     * }],
     * "first_page_url": "http://www.qipaoadmin.com/vip/gradebig?=1",
     * "from": 1,
     * "last_page": 1,
     * "last_page_url": "http://www.qipaoadmin.com/vip/gradebig?=1",
     * "next_page_url": null,
     * "path": "http://www.qipaoadmin.com/vip/gradebig",
     * "per_page": 20,
     * "prev_page_url": null,
     * "to": 7,
     * "total": 7
     * },
     * "message": ""
     * }
     */
    public function gradeBigList(Request $request)
    {
        $param = $request->only('page', 'page_size');
        $v = app('validator')->make($param, [
            'page' => 'integer|min:1',
            'page_size' => 'integer|min:1|max:100',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $page = $request->input('page', 1);
        $perPage = $request->input('page_size', 20);

        $list = app('repo_vip')->gradeBigList($page, $perPage);
        return Response::sendData($list);
    }

    /**
     * @api {get} /vip/gradebig/add/privilege 新增vip大等级特权列表
     * @apiVersion 0.1.0
     * @apiName 新增vip大等级特权列表
     * @apiGroup vip管理
     *
     * @apiParam {int} page 第几页，默认1
     * @apiParam {int} page_size 每页显示条数，1-100之间，默认10
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "current_page": 1,
     * "data": [{
     * "id": 5,
     * "name（特权名称）": "专属头像框",
     * }],
     * "first_page_url": "http://www.qipaoadmin.com/vip/privilege?=1",
     * "from": 1,
     * "last_page": 1,
     * "last_page_url": "http://www.qipaoadmin.com/vip/privilege?=1",
     * "next_page_url": null,
     * "path": "http://www.qipaoadmin.com/vip/privilege",
     * "per_page": 20,
     * "prev_page_url": null,
     * "to": 5,
     * "total": 5
     * },
     * "message": ""
     * }
     */
    public function gradeBigPrivilegeList(Request $request)
    {
        $param = $request->only('page', 'page_size');
        $v = app('validator')->make($param, [
            'page' => 'integer|min:1',
            'page_size' => 'integer|min:1|max:100',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $page = $request->input('page', 1);
        $perPage = $request->input('page_size', 20);

        $list = app('repo_vip')->gradeBigPrivilegeList($page, $perPage);
        return Response::sendData($list);
    }

    /**
     * @api {post} /vip/gradebig/add 新增vip大等级
     * @apiVersion 0.1.0
     * @apiName 新增vip大等级
     * @apiGroup vip管理
     *
     * @apiParam {int} grade 等级，必传
     * @apiParam {int} name 等级名称，必传
     * @apiParam {int} big_img 展示大图，必传
     * @apiParam {int} privilege_id 等级特权id json示例格式[1,2,3]，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function gradeBigAdd(Request $request)
    {
        $param = $request->only('grade', 'name', 'big_img', 'privilege_id');
        $v = app('validator')->make($param, [
            'grade' => 'required|integer|min:0|max:10000000',
            'name' => 'required|string|max:100',
            'big_img' => 'required|string|max:255',
            'privilege_id' => 'required|string|max:255',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_vip')->gradeBigAdd($param);
        return Response::sendData(true);
    }

    /**
     * @api {get} /vip/gradebig/edit_detail 编辑vip大等级数据
     * @apiVersion 0.1.0
     * @apiName 编辑vip大等级数据
     * @apiGroup vip管理
     *
     * @apiParam {Int} id id，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "id": 14,
     * "grade（阶段等级）": "12",
     * "name（名称）": "测试111",
     * "big_img（展示大图）": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/newadmin/17aec5df92d9cae5eebb9f046777cb7eDF078.png",
     * "privilege_id(特权id)": [
     * "1",
     * "2",
     * "3",
     * "4"
     * ]
     * },
     * "message": ""
     * }
     */
    public function gradeBigEditDetail(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_vip')->gradeBigEditDetail($param);
        return Response::sendData($list);
    }

    /**
     * @api {post} /vip/gradebig/edit 编辑vip大等级
     * @apiVersion 0.1.0
     * @apiName 编辑vip大等级
     * @apiGroup vip管理
     *
     * @apiParam {int} id id，必传
     * @apiParam {int} grade 等级，必传
     * @apiParam {int} name 等级名称，必传
     * @apiParam {int} big_img 展示大图，必传
     * @apiParam {int} privilege_id 等级特权id json示例格式[1,2,3]，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function gradeBigEdit(Request $request)
    {
        $param = $request->only('id', 'grade', 'name', 'big_img', 'privilege_id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
            'grade' => 'required|integer|min:0|max:10000000',
            'name' => 'required|string|max:100',
            'big_img' => 'required|string|max:255',
            'privilege_id' => 'required|string|max:255',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_vip')->gradeBigEdit($param);
        return Response::sendData(true);
    }

    /**
     * @api {post} /vip/gradebig/del 删除vip大等级
     * @apiVersion 0.1.0
     * @apiName 删除vip大等级
     * @apiGroup vip管理
     *
     * @apiParam {int} id id，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function gradeBigDel(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_vip')->gradeBigDel($param);
        return Response::sendData(true);
    }

}